import request from '@/axios'
import type { CurdData } from './types'

export const getListApi = (params: any) => {
  return request.get({ url: '/admin/inventory', params })
}

export const delListApi = (ids: string[] | number[]): Promise<IResponse> => {
  return request.delete({ url: '/admin/inventory', data: { ids } })
}

export const getInfoApi = (id: string): Promise<IResponse<CurdData>> => {
  return request.get({ url: '/admin/inventory/' + id })
}

export const saveDataApi = (data: Partial<CurdData>): Promise<IResponse> => {
  if (data.id) {
    return request.put({ url: '/admin/inventory/', data })
  } else {
    return request.post({ url: '/admin/inventory/', data })
  }
}
export const submitCheckApi = (data: Partial<CurdData>): Promise<IResponse> => {
  return request.post({ url: '/admin/inventory/submitCheckApi', data })
}
//获取币种下拉框数据
export const getCurrencyApi = (id: string): any => {
  return request.get({ url: `/admin/warehouse/getCurrencySelect?wid=${id}` })
}
//获取币种下拉框数据
export const getCurrencyEnumApi = (params?: any): any => {
  return request.get({ url: `/admin/warehouse/getCurrencySelect`, params })
}
//获取导入模版
export const getImportTemplateApi = (params = {}, filename: string): any => {
  return request.exportFile({ method: 'post', url: `/admin/template`, params, filename })
}
//编辑保存
export const saveEditApi = (data: any): any => {
  return request.post({ url: '/admin/inventory/fixSavePrice', data })
}
//获取详情数据
export const getDetailApi = (id: string): any => {
  return request.get({ url: `/admin/inventory/detail/${id}` })
}
export const getEditBackShowApi = (id: string): any => {
  return request.get({ url: `/admin/inventory/${id}` })
}
//获取转换回显数据
export const getConversionBackShowApi = (id: string, params?: any): any => {
  return request.get({ url: `/admin/inventory/transDetail/${id}`, params })
}
//获取转换列表回显数据
export const getConversionListApi = (data: any = {}): any => {
  return request.post({ url: `/admin/inventory/getOrderByInventory`, data })
}
//获取转换类型枚举
export const getConversionTypeApi = (id: string): any => {
  return request.get({ url: `/admin/inventory/transEnum/${id}` })
}
//提交转换表单
export const saveConversionApi = (data: any): any => {
  return request.post({ url: 'admin/inventory/transSave', data })
}
//导出
export const exportFileApi = (params = {}, filename: string) => {
  return request.exportFile({
    method: 'post',
    url: '/admin/inventory/exportPrice',
    params,
    filename
  })
}

export const saveBasketsApi = (data: any): any => {
  return request.post({ url: '/admin/inventory/baskets', data })
}
// 调仓
export const getInventoryByAbbrApi = (id: string) => {
  return request.get({ url: `/admin/order/getInventoryByAbbr/${id}` })
}
// 调仓
export const changeWarehouseApi = (data: any) => {
  return request.post({ url: `/admin/order/changeWarehouse`, data })
}

// 允许零库存销售开关
export const setAllowZeroStockSaleApi = (data: {
  ids: (string | number)[]
  allow_zero_stock_sale: 0 | 1
}): Promise<IResponse> => {
  return request.post({ url: 'admin/inventory/allowZero', data })
}
